package cn.com.bianguo.java.plugindemo.main.config;

import cn.com.bianguo.java.plugindemo.pluginimpl.IMessagePlugin;
import org.pf4j.PluginManager;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class PluginStarter implements CommandLineRunner {

    private final PluginManager pluginManager;

    public PluginStarter(PluginManager pluginManager) {
        this.pluginManager = pluginManager;
    }

    @Override
    public void run(String... args) throws Exception {
        //加载插件
        pluginManager.loadPlugins();
        //启动插件
        pluginManager.startPlugins();
        //获取所有拓展信息
        List<IMessagePlugin> plugins = pluginManager.getExtensions(IMessagePlugin.class);
        for (IMessagePlugin plugin : plugins) {
            plugin.sendMsg("我是一条消息");
        }
    }
}
